package org.redmaple.core.template.dao.hibernate;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.redmaple.core.template.dao.IDao;
import org.redmaple.core.template.model.BaseModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * DAO层抽象基类，只实现了获取sessionFactory及session的接口
 * 
 * @author Xiangyun
 *
 * @param <T>
 */
public abstract class DaoImpl<T extends BaseModel> implements IDao<T> {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	protected SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/**
	 * 取得当前 Session.
	 */
	public Session getSession() {
		return sessionFactory.getCurrentSession();
	}

}
